<?php
include "../../../lib/list.php";

if($_POST['mode']=='insert'){
	$id				=	clean($_POST['id']);
	$passwd			=	clean($_POST['passwd']);
	$name			=	clean($_POST['name']);	
	$authorize		=	clean($_POST['authorize']);
	$note			=	clean($_POST['note']);
		
		if(empty($id)){
			MsgViewLo("아이디를 입력해주세요.\\n내용입력에 실패했습니다.","view.php");
			return;
		}
		if(empty($passwd)){
			MsgViewLo("비밀번호를 입력해주세요.\\n내용입력에 실패했습니다.","view.php");
			return;
		}
		if(empty($name)){
			MsgViewLo("이름을 입력해주세요.\\n내용입력에 실패했습니다.","view.php");
			return;
		}
		
	else{
 		$query = sprintf("INSERT INTO `uniaimlogin`
 				(`id`, `pw`, `name`, `db_no`, `lv`, `authorize`, `note`) 
 				VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s');"
 				,$id, Encode64($passwd), $name, $_SESSION['IS_DB_IDX'],'3',$authorize,$note);
 		MDBquery($query);
	}
	mysql_close();
	MsgViewLo("관리자를 입력하였습니다.","view.php");
}

if($_POST['mode']=='modify'){
	$no				=	$_POST['no'];
	$name			=	$_POST['name'];	
	$authorize		=	$_POST['authorize'];
	$note			=	$_POST['note'];
	
	for($i=0;$i<count($no);$i++){
	
		$name[$i]			=	clean($name[$i]);
		$authorize[$i]		=	clean($authorize[$i]);
		$note[$i]			=	clean($note[$i]);
		
		if(empty($name)){
		MsgViewLo("이름을 입력해주세요.\\n내용입력에 실패했습니다.","view.php");
		return;
		}
				
		else{
			$query = sprintf("UPDATE `uniaimlogin` 
					SET `name`='%s', `authorize`='%s', `note`='%s' WHERE `no` = %d;",
			$name[$i],$authorize[$i],$note[$i],$no[$i]);
			MDBquery($query);
		}
	}
	mysql_close();
	MsgViewLo("관리자를 입력하였습니다.","view.php");
}

if($_POST['mode']=='delete'){

}